class Solution {
public:
    string minWindow(string s, string t) {
        int m = s.size(), n = t.size(), kinds = 0;
        vector<int> hash1(128), hash2(128); // 窗⼝字符的频次,t中字符频率
        for(auto& e : t)
        {
            if(hash2[e]++ == 0)
                ++kinds;
        }
        int left = 0, right = 0, cnt = 0, start = 0, minLen = INT_MAX;
        while(right < m)
        {
            char in = s[right];
            if(++hash1[in] == hash2[in]) // 进窗⼝ + 维护 cnt
                ++cnt;
            
            while(cnt == kinds) // 判断条件
            {
                if(right - left + 1 < minLen) // 更新结果
                {
                    minLen = right - left + 1;
                    start = left;
                }
                char out = s[left++];
                if(hash1[out]-- == hash2[out]) // 出窗⼝ + 维护 cnt
                    --cnt;
            }
            ++right;
        }
        return minLen == INT_MAX ? "" : s.substr(start, minLen);
    }
};